package com.example.arithmeticleetcode.leetcode.october;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-10-29 10:16
 **/
public class Demo19 {

    public static void main(String[] args) {
        int[][] arr1 = {{1,1},{2,2},{3,4},{4,5},{5,6},{7,7}};
        System.out.println(checkStraightLine(arr1));
    }

    public static boolean checkStraightLine(int[][] coordinates) {
        if (coordinates.length == 2) {
            return true;
        }

        BigDecimal rate = BigDecimal.valueOf(coordinates[1][1] - coordinates[0][1]).divide(BigDecimal.valueOf(coordinates[1][0] - coordinates[0][0]),4, RoundingMode.HALF_UP);
        System.out.println(rate);
        for(int i = 3, len = coordinates.length; i < len; i++) {
            System.out.println((coordinates[i][1] - coordinates[0][1]) + "=====" + (coordinates[i][0] - coordinates[0][0]));
            BigDecimal everyRate = BigDecimal.valueOf(coordinates[i][1] - coordinates[0][1]).divide(BigDecimal.valueOf(coordinates[i][0] - coordinates[0][0]), 4, RoundingMode.HALF_UP);
            System.out.println("-----" + everyRate);
            if (rate.compareTo(everyRate) != 0) {
                return false;
            }
        }
        return true;
    }
}
